﻿#include <iostream>

using namespace std;

#define  DELETE(pointer)  if(pointer){delete pointer; pointer=nullptr;}

class IProduct
{
public:
    virtual void Show() = 0;
};

class Apple :public IProduct
{
public:
    Apple() {};
    virtual ~Apple() {};
    void Show() { cout << "Apple" << endl; };
};

class Banana :public IProduct
{
public:
    Banana() {};
    virtual ~Banana() {};
    void Show() { cout << "Banana" << endl; };
};


class IFacory
{
public:
    virtual IProduct* CreateProduct() = 0;
};

class FactoryA :public IFacory
{
public:
    FactoryA() {}
    virtual ~FactoryA() {}

    IProduct* CreateProduct() override
    {
		return new Apple;
    }
};

class FactoryB :public IFacory
{
public:
    FactoryB() {}
    virtual ~FactoryB() {}

    IProduct* CreateProduct() override
    {
		return new Banana();
    }
};

int main()
{
    IFacory* factory = new FactoryA;
    IProduct* product = factory->CreateProduct();
    product->Show();
    DELETE(factory);
    DELETE(product);

    factory = new FactoryB;
    product = factory->CreateProduct();
    product->Show();
    DELETE(factory);
    DELETE(product);

    return 0;
}
